/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : bsp_hrtimer.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.03.22
  - Brief         : bsp hrtimer control
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2024.03.22       liuzhihua                  Create file          
***/

#ifndef BSP_HRTIMER_H
#define BSP_HRTIMER_H

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include <stdint.h>
#include "hrtim.h"
#ifdef  __cplusplus
    extern "C" {
#endif
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
#define DCDC_HV_HRTIM       HRTIM_TIMERID_TIMER_E
#define DCDC_LV_HRTIM       HRTIM_TIMERID_TIMER_B
#define DCDC_HV_HRTIM_ID    ('E' - 'A') // TIM_E
#define DCDC_LV_HRTIM_ID    ('B' - 'A') // TIM_B
#define DCDC_MOSL_ENABLE()  Pinx_RESET(PWM_LV_EN1)
#define DCDC_MOSH_ENABLE()  Pinx_RESET(PWM_HV_EN1)
#define DCDC_MOSL_DISABLE() Pinx_SET(PWM_LV_EN1)
#define DCDC_MOSH_DISABLE() Pinx_SET(PWM_HV_EN1)
#define DCDC_MOS_DISABLE()  do{Pinx_SET(PWM_HV_EN1);Pinx_SET(PWM_LV_EN1);}while(0)
#define DCDC_MOS_ENABLE()   do{Pinx_RESET(PWM_HV_EN1);Pinx_RESET(PWM_LV_EN1);}while(0)

#define DCDC_HV_GETFREQ()       bsp_HRTIM_GetFerq(DCDC_HV_HRTIM_ID)
#define DCDC_LV_GETFREQ()       bsp_HRTIM_GetFerq(DCDC_LV_HRTIM_ID)
#define DCDC_HV_GETDUTY()       bsp_HRTIM_GetDuty(DCDC_HV_HRTIM_ID)
#define DCDC_LV_GETDUTY()       bsp_HRTIM_GetDuty(DCDC_LV_HRTIM_ID)
#define DCDC_HV_SETFREQ(freq)   bsp_HRTIM_SetFerq(DCDC_HV_HRTIM_ID, (freq))
#define DCDC_HV_SETDUTY(duty)   bsp_HRTIM_SetDuty(DCDC_HV_HRTIM_ID, (duty))
#define DCDC_HV_SETDEAD(dead)   bsp_HRTIM_SetDead(DCDC_HV_HRTIM_ID, (dead))
#define DCDC_LV_SETFREQ(freq)   bsp_HRTIM_SetFerq(DCDC_LV_HRTIM_ID, (freq))
#define DCDC_LV_SETDUTY(duty)   bsp_HRTIM_SetDuty(DCDC_LV_HRTIM_ID, (duty))
#define DCDC_LV_SETDEAD(dead)   bsp_HRTIM_SetDead(DCDC_LV_HRTIM_ID, (dead))
#define DCDC_HV_PWM_Start()     HAL_HRTIM_WaveformCounterStart(&hhrtim1, DCDC_HV_HRTIM)
#define DCDC_HV_PWM_Stop()      HAL_HRTIM_WaveformCounterStop(&hhrtim1, DCDC_HV_HRTIM)
#define DCDC_LV_PWM_Start()     HAL_HRTIM_WaveformCounterStart(&hhrtim1, DCDC_LV_HRTIM)
#define DCDC_LV_PWM_Stop()      HAL_HRTIM_WaveformCounterStop(&hhrtim1, DCDC_LV_HRTIM)


/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
void bsp_HRTIM_Init(void);
void bsp_HRTIM_OutConfig(uint32_t TimerIdx, uint32_t freq, uint8_t duty);
void bsp_HRTIM_SetFerq(uint32_t TimerIdx, uint32_t freq);
void bsp_HRTIM_SetDuty(uint32_t TimerIdx, uint8_t duty);
void bsp_HRTIM_SetDead(uint32_t TimerIdx, uint32_t deadtime);
float bsp_HRTIM_GetFerq(uint32_t TimerIdx);
float bsp_HRTIM_GetDuty(uint32_t TimerIdx);


#ifdef __cplusplus
	}
#endif
#endif
